package cn.niit.service.impl;

import cn.niit.dao.StudentDao;
import cn.niit.entity.Student;
import cn.niit.entity.query.StudentQuery;
import cn.niit.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学生表(Student)表服务实现类
 *
 * @author makejava
 * @since 2021-11-14 16:07:43
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;


    @Override
    public PageInfo<Student> queryByStudent(StudentQuery studentQuery) {
        PageHelper.startPage(studentQuery.getPageNum(), studentQuery.getPageSize());
        return new PageInfo<Student>(studentDao.queryByStudent(studentQuery));
    }

    @Override
    public PageInfo<Student> queryByStudentName(StudentQuery studentQuery) {
        PageHelper.startPage(studentQuery.getPageNum(), studentQuery.getPageSize());

        return new PageInfo<Student>(studentDao.queryByStudentName(studentQuery));
    }



    @Override
    public PageInfo<Student> select(StudentQuery studentQuery) {
        PageHelper.startPage(studentQuery.getPageNum(),studentQuery.getPageSize());

        return new PageInfo<Student>(studentDao.select(studentQuery));
    }

    @Override
    public boolean editStudent(Student student) {
        int i = studentDao.editStudent(student);
        return i > 0;


    }

    @Override
    public Student queryStudentById(Integer id) {
        return studentDao.queryStudentById(id);
    }

    @Override
    public boolean addStudent(Student student) {
        return studentDao.addStudent(student) > 0;
    }


    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteStudentById(Integer id) {
        int i = studentDao.deleteStudentById(id);
        return i > 0;

    }

    /**
     * 查询所有学生信息
     */
    @Override
    public List<Student> queryAllStudentList() {
        return studentDao.queryByStudent(null);
    }
}